package com.javalab.recorder;

import java.util.ArrayList;
import java.util.List;

import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
import javax.sound.sampled.TargetDataLine;

public class SoundController {

	public List<Mixer.Info> getTargetDataLineMixerInfos() {
		Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
		Line.Info targetDataLineInfo = new Line.Info(TargetDataLine.class);
		List<Mixer.Info> mixerInfoList = new ArrayList<Mixer.Info>();
		for(Mixer.Info mixerInfo : mixerInfos) {
			Mixer mixer = AudioSystem.getMixer(mixerInfo);
			if (mixer.isLineSupported(targetDataLineInfo)) {
				mixerInfoList.add(mixerInfo);
			}
		}
		return mixerInfoList;
	}

	public TargetDataLine getTargetDataLine(Mixer.Info mixerInfo) {
		try {
			Mixer mixer = AudioSystem.getMixer(mixerInfo);
			return (TargetDataLine) mixer.getLine(new Line.Info(TargetDataLine.class));
		} catch (LineUnavailableException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
